package ru.urfc.portal.model.accounting;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import ru.urfc.portal.model.SpectrObjectWithContragent;
import ru.urfc.portal.ui.client.Constants;
import ru.urfc.portal.ui.client.model.catalogs.InvoiceState;

@Table(name = "portal_invoices")
@Entity
@XmlRootElement(name = Constants.INVOICE)
public class Invoice extends SpectrObjectWithContragent {
	private Contract contract;
	private String number;
	private String name;
	@Temporal(TemporalType.DATE)
	private Date date;
	@Column(scale = 2, precision = 16)
	public BigDecimal amount;
	@Column(scale = 2, precision = 16)
	public BigDecimal amountNds;
	@Column(scale = 2, precision = 16)
	public BigDecimal amountTotal;
	public Boolean isPaid;
	@Column(scale = 2, precision = 16)
	public BigDecimal debt;
	
	public Invoice() {
	}

	public Invoice(Contragent contragent, Contract contract, String number, String name, Date date,
			Double amount, Double amountNds, Double amountTotal, InvoiceState state, Double debt) {
		super(contragent);
		this.contract = contract;
		this.number = number;
		this.name = name;
		this.date = date;
		this.amount = new BigDecimal(amount);
		this.amountNds = new BigDecimal(amountNds);
		this.amountTotal = new BigDecimal(amountTotal);
		this.isPaid = state.equals(InvoiceState.PAID);
		this.amountTotal = new BigDecimal(debt);
	}

	@XmlElement
	public Contract getContract() {
		return contract;
	}
	
	@XmlElement
	public String getNumber() {
		return number;
	}
	
	@XmlElement
	public String getName() {
		return name;
	}
	
	@XmlElement
	public Date getDate() {
		return date;
	}
	
}
